<template>
<a-card :bordered="false">
    <a-spin :spinning="confirmLoading" v-if="isRegister">
        <LForm ref="registerForm" :formAttributes="formAttributes" :labelCol="labelCol" :wrapperCol="wrapperCol"></LForm>
        <a-button type="primary" block style="height:50px;margin-top:20px;" @click="handleOk">登记</a-button>
    </a-spin>

    <a-result v-else status="success" title="登记成功!">
        <template #extra>
            <a-button key="buy" @click="handleReturn">返回</a-button>
        </template>
    </a-result>
</a-card>

</template>

<script>
import LForm from '@/components/lt/form/LForm'
import request from '@/utils/request'

export default {
    name:'visitRegister',
    components:{
        LForm
    },
    data(){
        return{
            labelCol:{
                type:Object,
                default:()=>{
                    return {sm: { span: 10 }}
                }
            },
            wrapperCol:{
                type:Object,
                default:()=>{
                    return {sm: { span: 14 }}
                }
            },
            isRegister:true,
            title:'详情',
            confirmLoading: false,
            model:{},
            formAttributes:{
              type:'',//collapse,tabs
              formItems:[
                {
                  title:'标签一',
                  columns:1,
                  fields:[
                    {field:'visitName',label:'姓名',component:'input',rules: [{required: true, message: '来访人姓名不能为空'}]},
                    {field:'visitPhone',label:'手机号码',component:'inputNumber',rules: [{required: true,pattern: /^1[3|4|5|7|8][0-9]\d{8}$/, message: '请输入正确的手机号'}]},
                    {field:'isReserve',label:'是否预约',component:'radio',disabled:false,options:[{label: '是', value: '1'},{label: '否', value: '0'}],initialValue:'0'},
                    {field:'visitContent',label:'来访事由',component:'textarea',rules: [{required: true, message: '来访事由不能为空'}]},
                    {field:'intervieweeName',label:'受访者姓名',component:'input',rules: [{required: true, message: '受访者姓名不能为空!'}]},
                  ]
                },
              ]

            }


        }
    },
    methods:{
       
       
        handleOk(){
            const that = this;
            this.$refs.registerForm.getForm().validateFields((err, values) => {
                if (!err) {
                    that.confirmLoading = true
                    let formData = Object.assign(this.model, values);
                    request({url: '/ScVisitInfoController/save',method: 'post',data: formData}).then((res)=>{
                        if(res.success){
                            that.$message.success(res.message);
                            that.isRegister=false
                        }else{
                            that.$message.warning(res.message);
                        }
                    }).finally(() => {
                        that.confirmLoading = false;
                    })
                    
                }
            })
        },
        handleCancel(){
            this.visible=false
        },
        
        /**
         * 表单内容发生变化
         */
        handlerChange(changeItem){
            console.log(changeItem)
        },
        handleReturn(){
            this.isRegister=true
        }
    },
    created(){
        
    },
}
</script>

<style scoped>

</style>